<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>微信登陆回调页面</title>
    <script type="text/javascript" src="plugins/vue/dist/vue.js"></script>
    <script type="text/javascript" src="plugins/axios/dist/axios.js"></script>
    <script type="text/javascript" src="script/common.js"></script>
</head>
<body>
<div id="myDiv"></div>

<script type="text/javascript">
    new Vue({
        el:"#myDiv",
        mounted(){
            // 获取url中的code,调用后端接口
            let paramObj = urlToObj(location.href); //{code:"",state:""}
            this.$http.post("/login/wechat",paramObj)
                .then(result => {
                    result = result.data;
                    if(result.success){ // 登陆成功要将token和loginUser存入localStorage中
                        // 将token和loginUser存入localStorage中
                        localStorage.setItem("token",result.data.token);
                        localStorage.setItem("loginUser",JSON.stringify(result.data.loginUser));
                        alert("登陆成功!");
                        // 跳转到首页
                        location.href="/index.html";
                    }else{
                        if(result.message == "nobind"){ // 未绑定,要跳转到绑定页面并携带access_token以及openid
                            let {access_token,openid} = result.data;
                            location.href = "/binder.html?accessToken="+access_token+"&openid="+openid;
                        }else{
                            // 业务出错
                            alert(result.message);
                        }
                    }
                })
        }
    })
</script>
</body>
</html>